package sweetsaremeat.beehive.Controller;

import android.content.Context;
import android.view.MotionEvent;
import android.view.View;
import android.view.View.OnTouchListener;
import android.widget.Toast;
import sweetsaremeat.beehive.Model.Game;
import sweetsaremeat.beehive.View.GameAssets;
import sweetsaremeat.beehive.View.GameView;

public class MasterController {

	public GameView m_gameView;
	
	public Game m_game;
	
	public GameAssets m_gameAssets;
	
	public InputController m_inputController;
	
	public MasterController(Context a_context)
	{
		m_inputController = new InputController();
		
		m_game = new Game();
		m_inputController.SetGame(m_game);
		
		m_gameAssets = new GameAssets();
		m_gameAssets.LoadAssets();
		
		CreateView(a_context);
	}
	
	//needed when there is a new context
	public void CreateView(Context a_context)
	{
		//create the new game view
		m_gameView = new GameView(a_context, m_game, m_gameAssets);
		
		//set the view to the input controller
		m_inputController.SetView(m_gameView);
		
		//set the on touch event
		m_gameView.setOnTouchListener(new OnTouchListener()
        {
        	public boolean onTouch(View a_view, MotionEvent a_motionEvent) 
        	{
        		m_inputController.HandleMotion(a_view, a_motionEvent);
                return true;
            }
        });
		
		//test
		/*
		Toast.makeText(a_context, "IC: X=" + m_inputController.m_camera.m_pos.x + " Y=" + m_inputController.m_camera.m_pos.y, Toast.LENGTH_SHORT).show();
		Toast.makeText(a_context, "GV: X=" + m_gameView.m_camera.m_pos.x + " Y=" + m_gameView.m_camera.m_pos.y, Toast.LENGTH_SHORT).show();
		*/
	}
}
